package com.abc.io;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Iterator;
import java.util.TreeSet;

public class IoMian {

   public static void main(String[] args) {

      FileInputStream inputStream = null;
      Reader reader = null;
      BufferedReader br = null;

      try {
         inputStream = new FileInputStream("/Users/czy/Downloads/file20200617.txt");
         reader = new InputStreamReader(inputStream);
         br = new BufferedReader(reader);

         TreeSet<Double> result = new TreeSet<>();

         String strLine = null;
         while (null != (strLine = br.readLine())) {
            try {
               Double num = Double.parseDouble(strLine);
               result.add(num);

               if (result.size() > 100) {
                  result.remove(result.first());
               }
            }
            catch (Exception e) {
               e.printStackTrace();
            }
         }

         System.out.println(result.size());
         Iterator<Double> it = result.iterator();
         while (it.hasNext()) {
            Double db = it.next();
            System.out.println(db);
         }
      }
      catch (IOException e) {
         e.printStackTrace();
      }
      finally {
         try {
            inputStream.close();
            br.close();
         }
         catch (IOException e) {
            e.printStackTrace();
         }
      }
   }


}
